package com.mycompany.myapp.qrcode;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.mycompany.myapp.domain.ElectricBicycle;

import java.io.File;
import java.util.Hashtable;
import java.util.List;

/**
 * Create by wys on 2018/7/25
 */
public class ElecBicycleIDQRcode {

    public String getelecBicycleIDQRcode(List<ElectricBicycle> electricBicycles) {

        try {
            for(ElectricBicycle electricBicycle:electricBicycles) {

                String text = electricBicycle.getElectricBicycleID();
                int width = 100;
                int height = 100;
                String format = "png";
                Hashtable hints= new Hashtable();
                hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
                BitMatrix bitMatrix = new MultiFormatWriter().encode(text,BarcodeFormat.QR_CODE,
                    width,height,hints);
                String str = "E:\\721\\sharedelectricbicycle\\src\\main\\resources\\static\\qrcode\\";
                String qrcodeName = electricBicycle.getElectricBicycleID();
              //  File outputFile = new File("C:\\Users\\12192\\Desktop\\elecbicycleIDQRcode\\new.png");
                File outputFile = new File(str+qrcodeName+".png");
                MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
            }

        }catch (Exception e) {

        }

        return "no_exception";
    }


}
